#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <list>

#define endl '\n'

using namespace std;

typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef pair<string, int> psi;

typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pss> vpss;
typedef vector<vi> vvi;

typedef queue <int> qi;
typedef queue <ll> ql;
typedef queue <pii> qpii;
typedef queue <psi> qpsi;

typedef priority_queue<int> pqi;
typedef priority_queue<string> pqs;
typedef priority_queue<pii> pqpii;
typedef priority_queue<psi> pqpsi;

typedef unordered_map<int, int> umapii;
typedef unordered_map<string, int> umapsi;

const int N = 3e5 + 5;

typedef struct node
{
	int temp;
	int con;
	node() { temp = INT32_MAX; con = 0; }
} node;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<node> cons(n + 1);
	vpii a;
	int fi, ft, li, lt, x;
	for (int i = 0; i < k; i++)
	{
		cin >> x;
		a.push_back({ x,INT32_MAX });
	}
	for (int i = 0; i < k; i++)
	{
		cin >> x;
		a[i].second = x;
	}
	sort(a.begin(), a.end());
	fi = a[0].first;
	ft = a[0].second;
	li = a.back().first;
	lt = a.back().second;
	for (int i = 0; i < a.size(); i++)
	{
		cons[a[i].first].con = a[i].second;
		cons[a[i].first].temp = a[i].second;
	}
	int now = ft;
	for (int i = fi; i <= n; i++)
	{
		if (cons[i].con)
		{
			if (now > cons[i].con)
				now = cons[i].con;
		}
		if (now < cons[i].temp)
			cons[i].temp = now;
		now++;
	}
	now = lt;
	for (int i = li; i >= 1; i--)
	{
		if (cons[i].con)
		{
			if (now > cons[i].con)
				now = cons[i].con;
		}
		if (now < cons[i].temp)
			cons[i].temp = now;
		now++;
	}
	for (int i = 1; i <= n; i++)
	{
		cout << cons[i].temp << " ";
	}
	cout<<endl;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}